package servlet.salary;

import bean.Salary;
import dao.SalaryDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by young on 2017/6/26.
 */
@WebServlet(name = "UpdateSalary", urlPatterns = "/updateSalary")
public class UpdateSalary extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setHeader("content-type", "text/html;charset=UTF-8");
        Salary salary = new Salary();
        salary.setId(Integer.parseInt(request.getParameter("salaryId")));
        salary.setMoney(Integer.parseInt(request.getParameter("Salary")));
        SalaryDao salaryDao = new SalaryDao();
        int row = salaryDao.updateSalary(salary);
        if (row != 0) {
            response.sendRedirect("/salaryManager.jsp");
        } else {
            response.sendRedirect("/errorPage.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
